RISCVCC = riscv32-unknown-elf-gcc
RISCVAS = riscv32-unknown-elf-as
RISCVLD = riscv32-unknown-elf-ld
RISCVOBJCOPY = riscv32-unknown-elf-objcopy
RISCVOBJDUMP = riscv32-unknown-elf-objdump
B2D = python3 BinToMem_CLI.py
B2M = python3 BinToMif_CLI.py
RISCVOBJECTS = uart.o

all: test.data test.mif

s: *.c
	$(RISCVCC)  -march=rv32i -mabi=ilp32 -S $<
%.o: %.s s
	$(RISCVAS) -march=rv32i $< -o $@

mem.om: ram.ld $(RISCVOBJECTS)
	$(RISCVLD) -T ram.ld $(RISCVOBJECTS) -o $@ 

test.bin: mem.om
	$(RISCVOBJCOPY) -O binary $< $@

objdump: mem.om
	$(RISCVOBJDUMP) -D $<
	
test.data: test.bin
	$(B2D) $< $@

test.mif: test.bin
	$(B2M) $< $@
	
clean:
	rm -f *.o *.om *.bin *.data *.mif


